//
//  YSGMyopiaReserveCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/1/5.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class YSGMyopiaReserveCell: UITableViewCell {
    
    var type: MyopiaReserveCellType = .text
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var memoLabel: UILabel! {
        didSet {
            memoLabel.adjustsFontSizeToFitWidth = true
        }
    }
    @IBOutlet weak var selectImgView: UIImageView!
    @IBOutlet weak var arrowImgView: UIImageView!
    
    func updateCellWithVm(vm: MyopiaReserveViewModel, indexPath: IndexPath) {
        memoLabel.isHidden = vm.reserveCellType(indexPath: indexPath).hiddenText
        selectImgView.isHidden = vm.reserveCellType(indexPath: indexPath).hiddenButton
        arrowImgView.isHidden = vm.reserveCellType(indexPath: indexPath).hiddenArrow
        
        titleLabel.text = vm.titleForCell(indexPath: indexPath)
        memoLabel.text = vm.memoForCell(indexPath: indexPath)
        selectImgView.image = UIImage(named: vm.selectedImgForCell(indexPath: indexPath))
        
        resetLayer()
        if let corners = vm.cornersForCell(indexPath: indexPath) {
            setLayer(corners: corners)
        }
    }
    
    func setLayer(corners: UIRectCorner) {
        bgView.layerCorners(rect: bgView.frame, radius: 16, corners: corners)
    }
    
    func resetLayer() {
        bgView.layerCorners(rect: bgView.frame, radius: 0, corners: .allCorners)
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
